var a = require("../../../../@babel/runtime/helpers/objectSpread2"), t = require("../../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        activeName: 0,
        dataList: [],
        titleArr: [],
        cardTotal: "---",
        isLoadMore: !0,
        showActivePop: !1,
        groupList: [],
        selectGroupId: null
    },
    onLoad: function(a) {
        this.initOptions();
    },
    initOptions: function() {
        var a = this, e = "plugin.ywm-fight-groups.frontend.controllers.fight-groups.get-member-join-teams";
        this.data.dataList = [], this.data.titleArr = [ {
            name: "正在拼团",
            url: e,
            param: {
                team_status: 1
            }
        }, {
            name: "拼团成功",
            url: e,
            param: {
                team_status: 2
            }
        }, {
            name: "拼团失败",
            url: e,
            param: {
                team_status: 3
            }
        }, {
            name: "我的开团卡",
            url: "plugin.ywm-fight-groups.frontend.controllers.fight-groups.my-open-group-card",
            param: {},
            callback: function(e) {
                a.data.isLoadMore = !0, a.data.dataList[a.data.activeName].isLoadMore = !0, a.data.dataList[a.data.activeName].total_page = e.data.last_page, 
                a.data.dataList[a.data.activeName].page = e.data.current_page, a.setData(t({
                    cardTotal: e.card_number
                }, "dataList[" + a.data.activeName + "].list", a.data.dataList[a.data.activeName].list.concat(e.data.data)));
            }
        } ], this.setData({
            titleArr: this.data.titleArr
        }), this.initData();
    },
    initData: function() {
        var a = this;
        this.data.dataList = [], this.data.isLoadMore = !0, this.data.titleArr.forEach(function(t, e) {
            a.data.dataList.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: []
            });
        }), this.getData();
    },
    onChange: function(a) {
        this.setData({
            activeName: a.detail.index
        }), this.getData();
    },
    getData: function() {
        var i = this;
        if (!(this.data.dataList[this.data.activeName].list.length > 0)) {
            var s = a({}, this.data.titleArr[this.data.activeName].param), r = this.data.titleArr[this.data.activeName].url;
            e._getNetWork({
                url: e.getNetAddresss(r),
                data: s,
                success: function(a) {
                    var s = a.data;
                    if (1 == s.result) {
                        if (i.data.titleArr[i.data.activeName].callback) return i.data.titleArr[i.data.activeName].callback(s.data);
                        i.data.isLoadMore = !0, i.data.dataList[i.data.activeName].isLoadMore = !0, i.data.dataList[i.data.activeName].total_page = s.data.last_page, 
                        i.data.dataList[i.data.activeName].page = 1, i.setData(t({}, "dataList[" + i.data.activeName + "].list", s.data.data));
                    } else e.tips(res.msg);
                }
            });
        }
    },
    clickBtn: function(a) {
        var t = a.target.dataset, e = t.value, i = t.id, s = t.orderid, r = (t.good, t.tid);
        switch (Number(e)) {
          case 2:
            s && this.gotoOrder(s);
            break;

          case 3:
            this.gotoGroup(r);
            break;

          case 4:
            this.data.selectGroupId = i, this.getActiveList();
            break;

          case 5:
            this.gotoGroupList(i);
        }
    },
    gotoGroupList: function(a) {
        wx.navigateTo({
            url: "/packageB/member/group/GroupList/GroupList?id=" + a + "&types=ywmGroup"
        });
    },
    gotoOrder: function(a) {
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + a + "&orderType=ywmgroups"
        });
    },
    gotoGroup: function(a) {
        wx.navigateTo({
            url: "/packageB/member/group/GroupDetail/GroupDetail?id=" + a + "&plu=ywm"
        });
    },
    getActiveList: function() {
        var a = this;
        e._getNetWork({
            url: e.getNetAddresss("plugin.ywm-fight-groups.frontend.controllers.fight-groups.index"),
            data: {},
            success: function(t) {
                var i = t.data;
                1 == i.result ? a.setData({
                    groupList: i.data.data,
                    showActivePop: !0
                }) : e.tips(res.msg);
            }
        });
    },
    openTeam: function(a) {
        var t = a.detail, e = t.id, i = t.title, s = this;
        wx.showModal({
            title: "提示",
            content: "是否确认选中【".concat(i, "】开团"),
            success: function(a) {
                a.confirm && s.openTeamQuest(e);
            }
        });
    },
    openTeamQuest: function(a) {
        var t = this;
        e._getNetWork({
            url: e.getNetAddresss("plugin.ywm-fight-groups.frontend.controllers.fight-groups.auto-open-group"),
            data: {
                team_member_id: this.data.selectGroupId,
                group_id: a
            },
            success: function(a) {
                var i = a.data;
                e.tips(i.msg), 1 == i.result && (t.setData({
                    showActivePop: !1
                }), t.initData());
            }
        });
    },
    hiddenActivePop: function() {
        this.setData({
            showActivePop: !1
        });
    },
    onClickRight: function() {
        wx.navigateTo({
            url: "/packageB/member/group/ywmGroupsDetailed/ywmGroupsDetailed"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.dataList[this.data.activeName].isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    _getMoreData: function() {
        var i = this;
        if (this.data.dataList[this.data.activeName].isLoadMore = !1, !(this.data.dataList[this.data.activeName].page >= this.data.dataList[this.data.activeName].total_page)) {
            var s = a({}, this.data.titleArr[this.data.activeName].param), r = this.data.titleArr[this.data.activeName].url, o = this.data.dataList[this.data.activeName].page + 1, d = e.getNetAddresss(r);
            d = d + "&page=" + o, e._getNetWork({
                url: d,
                data: s,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var s = e.data.data;
                        if (i.data.titleArr[i.data.activeName].callback) return i.data.titleArr[i.data.activeName].callback(e.data);
                        i.data.dataList[i.data.activeName].isLoadMore = !0, i.data.dataList[i.data.activeName].page = o, 
                        i.setData(t({}, "dataList[" + i.data.activeName + "].list", i.data.dataList[i.data.activeName].list.concat(s)));
                    } else i.data.dataList[i.data.activeName].isLoadMore = !1;
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    onShareAppMessage: function(a) {
        var t = wx.getStorageSync("yz_uid"), e = "";
        if (t && (e = t), a && "button" == a.from) {
            var i = a.target.dataset, s = "/packageB/member/group/GroupDetail/GroupDetail?id=" + i.tid + "&plu=ywm&mid=" + e;
            return {
                title: i.good.title,
                path: s
            };
        }
    }
});